<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>个人中心</title>

	<link rel="stylesheet" href="/dist/css/bootstrap.min.css">
	<script src="/dist/js/jquery.min.js"></script>
	<script src="/dist/js/bootstrap.min.js"></script>
	<script src="/dist/js/holder.min.js"></script>
	<script src="/dist/js/application.min.js"></script>

	<style>
	li {
		list-style:none;
	}
	.cur{
		border:solid 2px purple;
	}

	</style>
</head>
<body>
      @include('/home/menu')
	<div class="container zero">
	    <div class="col-md-offset-1 ">
			  <ul class="nav nav-tabs" role="tablist">
				  <li role="presentation" ><a href="/people/setting">基本信息</a></li>
				  <li role="presentation" class="active"><a href="#">账号和密码</a></li>
				  <li role="presentation"><a href="#">消息和邮件</a></li>
				  <li role="presentation"><a href="#">屏蔽</a></li>
				  <li role="presentation"><a href="#">实验室</a></li>
				  <li role="presentation"><a href="#">有待开发</a></li>
			  </ul>
		</div>

			   
	        <div class="col-md-offset-1">
				<div class="list-group col-xs-10 col-sm-8 col-md-7 col-lg-7">
					  <a href="#" class="list-group-item active">
					    绑定手机和邮箱，并设置密码，帐号更安全。
					  </a>
						<a href="#" class="list-group-item">
							<span >手机:</span>
						  	<span>{{$ress->phone}}&nbsp;&nbsp;&nbsp;</span>
						  	
						</a>
						<a href="#" class="list-group-item">
							 <span >邮箱:</span>
						  	<span id='email'>{{$ress->email}}</span>
						</a>
						<a href="#" class="list-group-item">
							 <span >密码:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	</span>
							 <input type="password"  name="password" id='pwd'>
							 <span id="textpwd"></span>
						</a>
						<a href="#" class="list-group-item">
							 <span >确认密码:</span>
							 <input type="password"  name="repassword" id="repwd">&nbsp;&nbsp;&nbsp;	
							 <span id="textrepwd"></span>
							 {{ csrf_field() }} 

						</a>
						<a href="#" class="list-group-item">
							 <button type="submit" class="btn btn-info" id="butpwd">确认</button>
						</a>
				    
							
				</div>
			</div>
	</div>

		  <script>
		  // alert($);
	    
                    var PASSWORD = 0, REPASSWORD = 0;
			   	 	$('input[name=password]').focus(function(){
			    	$(this).addClass('cur');
			    })

			    //失去焦点 blur
			    $('input[name=password]').blur(function(){
			    	//获取值
			    	var pv = $(this).val();
			    	//正则
			    	var reg = /^\w{6,12}$/;
			    	//检测
			    	var res = reg.test(pv);//返回boolean
			    	if(!res){
			    		$(this).css('border','solid 2px red');
			    	 	$("#textpwd").html('<span style="color:red">格式错误:请输入6~12位密码</span>');
			    	 	PASSWORD = 0;
			    	} else {
			    		$(this).css('border','solid 2px green');
			    	 	$("#textpwd").html('<span style="color:green">√</span>');
			    	 	PASSWORD = 1;


			    	}
			    })


			    //确认密码
			    $('input[name=repassword]').focus(function(){
			    	$(this).addClass('cur');
			    })

			    //失去焦点
			    $('input[name=repassword]').blur(function(){
			    	//获取第一次输入的密码
			    	var pv = $('input[name=password]').val();
			    	// console.log(pv);
			    	//获取确认密码
			    	var rpv = $(this).val();
			    	//判断
			    	if(pv != rpv){
			    	

			    		$('#textrepwd').html('<span style="color:red">两次输入的密码不一样</span>');//两个密码框都提示
			    		$(this).css('border','solid 2px red');
			    	 	REPASSWORD = 0;
			    	} else { 
			    		

			    		$('#textrepwd').html('<span style="color:green">√</span>');//两个密码框都提示
			    		$(this).css('border','solid 2px green');
			    	 	REPASSWORD = 1;

			    	}
			    })
			 
			  
				  $('#butpwd').click(function(){
				  	 if(REPASSWORD && PASSWORD){
				  	var password = pwd.value;
				  	$.post('/people/updatemm',{'_token':'{{csrf_token()}}','password':password},function(data){
				  		// alert('成功');

				  		// var_dump(data);die;
				  		// alert(data);
				  		// console.log(typeof(data));
				  		if(data == 0){

				  			alert('密码修改失败1');
				  		}else{
		  			      document.write(data);
				  			


				  		}
				  	});//'_token':'{{csrf_token()}}' post发送ajax 发送的数据中必须加这个
		            // console.log(pwd.value);//原生写法直接 id.value 就可以拿到input的值
		            // console.log(repwd.value);
		    
		             

                     }else{
                     	alert('请填写正确密码');
                     }
				  });
		  
		  </script>



	
</body>
</html>